﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApp1
{
    public static class Class1
    {
        public static string ToSHA1(this string code)
        {
            return BitConverter.ToString(new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(code))).ToUpper().Replace("-", "");
        }
    }
    public abstract class SubscribeRequest
    {
        /// <summary>
        /// 请求Id
        /// </summary>
        public string RequestId { get; set; }
        /// <summary>
        /// 时间戳
        /// </summary>
        public long Timestamp { get; set; }
        /// <summary>
        /// 签名
        /// </summary>
        public string Sign { get; set; }
        public abstract int GetProjectId();
        public abstract string GetBizNo();
        public abstract string GetCode();
    }
    public class StandingbookBillDetailPushRequest : SubscribeRequest
    {
        public StandingbookBillDetailPushRequest()
        {
            this.Standingbooks = new List<StandingbookPushDto>();
        }

        /// <summary>
        /// 项目Id
        /// </summary>
        public int ProjectId { get; set; }
        /// <summary>
        /// 项目编码
        /// </summary>
        public string ProjectCode { get; set; }
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName { get; set; }
        /// <summary>
        /// 项目简称
        /// </summary>
        public string ProjectShortName { get; set; }


        public List<StandingbookPushDto> Standingbooks { get; set; }

        public override string GetBizNo()
        {
            if (Standingbooks?.Any() == true)
            {
                return string.Join("|", Standingbooks.Select(x => x.BusinessNumber));
            }
            return "";
        }

        public override string GetCode()
        {
            if (Standingbooks?.Any() == true)
            {
                return string.Join("|", Standingbooks.Select(x => x.Code));
            }
            return "";
        }

        public override int GetProjectId()
        {
            return this.ProjectId;
        }
    }
    public class StandingbookPushDto
    {
        public StandingbookPushDto()
        {
            this.BillingDetails = new List<BillingDetailPushDto>();
        }
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 业务单号
        /// </summary>
        public string BusinessNumber { get; set; }
        /// <summary>
        /// 作业类型编码
        /// </summary>
        public string BusinessTypeCode { get; set; }
        /// <summary>
        /// 业务发生时间
        /// </summary>
        public long BizTime { get; set; }
        /// <summary>
        /// 客户编码
        /// </summary>
        public string CustomerCode { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public int V { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public long CreatedOn { get; set; }
        /// <summary>
        /// 明细
        /// </summary>
        public List<BillingDetailPushDto> BillingDetails { get; set; }
    }
    public class BillingDetailPushDto
    {

        /// <summary>
        /// 协议Id
        /// </summary>
        public int ContractId { get; set; }
        /// <summary>
        /// 协议编码
        /// </summary>
        public string ContractCode { get; set; }
        /// <summary>
        /// 客户Id
        /// </summary>
        public int CustomerId { get; set; }
        /// <summary>
        /// 客户编码
        /// </summary>
        public string CustomerCode { get; set; }
        /// <summary>
        /// 客户名称
        /// </summary>
        public string CustomerName { get; set; }
        /// <summary>
        /// 社会信用代码
        /// </summary>
        public string SocialCreditCode { get; set; }
        /// <summary>
        /// 是否含税
        /// </summary>
        public bool IsIncludeTax { get; set; }

        /// <summary>
        /// 明细结算项编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 业务类型
        /// </summary>
        public string BusinessType { get; set; }
        /// <summary>
        /// 结算项编码
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        public decimal Amount { get; set; }
        /// <summary>
        /// 税率
        /// </summary>
        public decimal? Tax { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public long CreatedOn { get; set; }
    }
}
